package com.beardedhen.harmonybootstrap.utils;

import ohos.agp.colors.RgbColor;
import ohos.app.Context;

/**
 * Utils class for manipulating Bootstrap colors, and resolving colors from resource values.
 */
public class ColorUtils {

    public static final int DISABLED_ALPHA_FILL = 165;
    public static final int DISABLED_ALPHA_EDGE = 190;
    public static final float ACTIVE_OPACITY_FACTOR_FILL = 0.125f;
    public static final float ACTIVE_OPACITY_FACTOR_EDGE = 0.025f;
    private static final String TAG = "ColorUtils";

    /**
     * Resolves a color resource.
     *
     * @param color   the color resource
     * @param context the current context
     * @return a color int
     */
    @SuppressWarnings("deprecation")
    public static int resolveColor(int color, Context context) {
        return ResUtil.getColor(context,color);
    }

    /**
     * Darkens a color by reducing its RGB channel values.
     *
     * @param context the current context
     * @param res     the color resource
     * @param percent the percent to decrease
     * @return a color int
     */
    public static int decreaseRgbChannels(Context context, int res, float percent) {
        RgbColor rgb = RgbColor.fromArgbInt(ResUtil.getColor(context, res));
        int alpha =  rgb.getAlpha();

        // reduce rgb channel values to produce box shadow effect
        int red = (rgb.getRed());
        red -= (red * percent);
        red = red > 0 ? red : 0;

        int green = (rgb.getGreen());
        green -= (green * percent);
        green = green > 0 ? green : 0;

        int blue = (rgb.getBlue());
        blue -= (blue * percent);
        blue = blue > 0 ? blue : 0;

        RgbColor argb = new RgbColor(red, green, blue, alpha);

        return argb.asArgbInt();
    }

    public static int increaseOpacityFromInt(Context context, int c, int
            alpha) {
        RgbColor rgb = RgbColor.fromArgbInt(c);
        rgb.setAlpha(alpha);
        return rgb.asArgbInt();
    }
}
